package com.bgybmi.controller.repair;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.bgybmi.entity.BxImgCreate;
import com.bgybmi.util.ApiUtil;
import com.bgybmi.util.RescouceReader;
import com.jfinal.qyweixin.sdk.api.OAuthApi;
import com.sun.jndi.dns.ResourceRecord;

public class BxThread extends Thread{
	
	private String serverIds;
	
	private int bxid;
	
	private static String savePath=RescouceReader.getProperties("config").getString("ImagePath");
	
	public BxThread(String serverIds,int bxid){
		this.serverIds=serverIds;
		this.bxid=bxid;
	}
	
	@Override
	public void run() {
		String server[]=StringUtils.split(serverIds,",");
		if(null!=server){
			for (int i = 0; i < server.length; i++) {
				//ser.();
				String serverId=server[i];
				String path=getNewPath(savePath);
				//下载图片从服务器信息
				Boolean flag = ApiUtil.getMedia(serverId, path);				
				if(flag==true){
					System.out.println(path);
					BxImgCreate bxc=new BxImgCreate();
					bxc.set("bx_id",bxid);
					bxc.set("imgpath",path);
					bxc.set("imgname",serverId);
					bxc.save();
				}
			}
		}

	}
	
    private String getNewPath(String savePath){
    	Date date = new Date();
    	Calendar c=Calendar.getInstance();
    	int year=c.getWeekYear();
/*		int year=date.getTime();*/
		String part = savePath+"/"+ year + "/" ;
		File file = new File(part);	
		if (!file.exists()){
			file.mkdirs();
		}
		return part;
    } 
	
    public static void main(String[] args) {
		Calendar c=Calendar.getInstance();
		System.out.println(c.getWeekYear());
	}
}
